package com.rainng.coursesystem.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rainng.coursesystem.base.api.dto.BaseIdReqDTO;
import com.rainng.coursesystem.base.api.dto.BaseIdsReqDTO;
import com.rainng.coursesystem.base.api.dto.PagingReqDTO;
import com.rainng.coursesystem.config.themis.annotation.Admin;
import com.rainng.coursesystem.controller.BaseController;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import com.rainng.coursesystem.module.custom.dto.request.CustomQueryReqDTO;
import com.rainng.coursesystem.module.custom.dto.request.CustomReqDTO;

import com.rainng.coursesystem.module.custom.dto.response.CusDicResDTO;
import com.rainng.coursesystem.module.custom.dto.response.CustomResDTO;
import com.rainng.coursesystem.module.custom.service.CustomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.rainng.coursesystem.module.task.dto.request.customerReqDTO;

import javax.annotation.Resource;
import java.util.List;


@Admin(Admin.CLASS_MANAGE)
@RequestMapping("/v2/sys/custom")
@RestController
@Api(tags = "客户管理")
public class CustomController extends BaseController {

    @Resource
    private CustomService baseService;

    /**
     * 分页查询数据
     * @param reqDTO
     * @return
     */
    @PostMapping("/paging")
    @ApiOperation(value = "客户管理数据分页查询")
    public ResultVO<IPage<CustomResDTO>> paging(@RequestBody PagingReqDTO<CustomQueryReqDTO> reqDTO){
        IPage<CustomResDTO> page = baseService.paging(reqDTO);
        return super.result(page);
    }

    /**
     * 保存用户
     * @param reqDTO
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "客户管理数据新增或更新")
    public ResultVO save(@RequestBody CustomReqDTO reqDTO){
        baseService.save(reqDTO);
        return super.result();
    }

    /**
     * 批量删除用户
     * @param reqDTO
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "客户管理数据删除")
    public ResultVO delete(@RequestBody BaseIdsReqDTO reqDTO){
        baseService.delete(reqDTO.getIds());
        return super.result();
    }

    /**
     * 查看详情
     * @param reqDTO
     * @return
     */
    @PostMapping("/detail")
    @ApiOperation(value = "客户管理数据详情")
    public ResultVO<CustomResDTO> detail(@RequestBody BaseIdReqDTO reqDTO){
        CustomResDTO custom = baseService.getCustomById(reqDTO.getId());
        return super.result(custom);
    }
    @PostMapping("/getUserByCustomer")
    @ApiOperation(value = "根据厂家信息查询主检")
    public ResultVO<CustomResDTO> getUserByCustomer(@RequestBody CustomReqDTO reqDTO){
        List<CustomResDTO> user = baseService.getUserByCustomer(reqDTO.getId());
        return super.result(user);
    }
    /**
     * 展示所有客户(id,groupName)
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "客户管理展示所有企业名称")
    public ResultVO<List<CusDicResDTO>> list(){
        List<CusDicResDTO> resDTOS = baseService.getList();
        return super.result(resDTOS);
    }





//    private final ClassService service;
//
//    public ClassController(ClassService service) {
//        this.service = service;
//    }
//
//    @GetMapping("/{id}")
//    public ResultVO get(@PathVariable Integer id) {
//        return service.get(id);
//    }
//
//    @PostMapping
//    public ResultVO create(@RequestBody @Validated ClassEntity entity) {
//        return service.create(entity);
//    }
//
//    @DeleteMapping("/{id}")
//    public ResultVO delete(@PathVariable Integer id) {
//        return service.delete(id);
//    }
//
//    @PutMapping
//    public ResultVO update(@RequestBody @Validated ClassEntity entity) {
//        return service.update(entity);
//    }
//
//    @RequestMapping("/page/count")
//    public ResultVO getPageCount(String departmentName, String majorName, String name) {
//        return service.getPageCount(departmentName, majorName, name);
//    }
//
//    @RequestMapping("/page")
//    public ResultVO getPage(String departmentName, String majorName, String name) {
//        return service.getPage(1, departmentName, majorName, name);
//    }
//
//    @RequestMapping("/page/{index}")
//    public ResultVO getPage(@PathVariable Integer index, String departmentName, String majorName, String name) {
//        return service.getPage(index, departmentName, majorName, name);
//    }
//
//    @Admin
//    @RequestMapping("/names")
//    public ResultVO listName() {
//        return service.listName();
//    }
}
